package com.weipt.juc.function;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @author peter.wei 2020/09/28 13:15
 * @version 1.0
 * @company 终生学习
 * @description <br>peter.wei 2020/09/28 13:15
 *
 * Consumer消费传入的参数
 **/
public class TestConsumer {
    public static void main(String[] args) {
        Consumer<String> innerConsumer = new Consumer<String>() {
            @Override
            public void accept(String o) {
                System.out.println(o);    //匿名内部类，重写accept方法
            }
        };
        innerConsumer.accept("111");   //调用accept方法

        // lambda表达式实现
        Consumer<String> consumer = (str)->{
            System.out.println(str);
        };
        consumer.accept("222");


        BiConsumer<String, String> innnerBiConsumer = new BiConsumer<String, String>() {
            @Override
            public void accept(String o, String o2) {
                System.out.println("参数1："+o);
                System.out.println("参数2："+o2);
            }
        };
        innnerBiConsumer.accept("1", "2");


        BiConsumer<String, String> biConsumer = (t, u) -> {
            System.out.println("参数1：" + t);
            System.out.println("参数2：" + u);
        };
        biConsumer.accept("1", "2");

        testBiConsumer((t,u)->{
            System.out.println("参数1：" + t);
            System.out.println("参数2：" + u);
        });
    }



    public static void testBiConsumer(BiConsumer<String, String> biConsumer){
        biConsumer.accept("111", "222");
    }
}